package com.hdu.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 结果-restful
 * @param
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class Result<T> {

    private boolean success; // 是否成功
    private Integer code; // 返回码
    private String message; // 返回信息
    private T data; // 返回数据

    public Result(ResultCode code) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
    }

    public Result(ResultCode code, T data) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
        this.data = data;
    }

    public static <T> Result<T> fail() {
        return new Result<>(ResultCode.FAIL);
    }
    public static <T> Result<T> success(T object){
        Result<T> result=new Result<>();
        result.data=object;
        result.code=1;
        return result;
    }

    public static <T> Result<T> error(String msg){
        Result<T> result=new Result<T>();
        result.message=msg;
        result.code=0;
        return result;
    }



}